package com.liull.netty.lagou;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

import java.nio.charset.StandardCharsets;

/**
 * @Author: liull
 * @Description:
 * @Date: Created in 16:10 2021/7/22
 * @Modified By:
 */
public class ResponseSampleEncoder extends MessageToByteEncoder<ResponseSample> {
    @Override
    protected void encode(ChannelHandlerContext ctx, ResponseSample msg, ByteBuf out) throws Exception {
        if (msg != null) {
            out.writeBytes(msg.getCode().getBytes(StandardCharsets.UTF_8));
            out.writeBytes(msg.getData().getBytes(StandardCharsets.UTF_8));
            out.writeLong(msg.getTimestamp());
        }
    }
}
